package iot.entity;

import com.datastax.driver.core.utils.UUIDs;
import com.datastax.driver.mapping.annotations.ClusteringColumn;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
import com.datastax.driver.mapping.annotations.Transient;
import iot.disruptor.EventData;
import iot.jtt808.DataPack;
import iot.jtt808.terminal.LocationReport;

import java.util.Date;
import java.util.UUID;

/**
 * Created by dave on 18-7-21 上午12:39.
 */
@Table(keyspace = "iot", name = "location")
public class Location implements EventData<Location> {
    @PartitionKey
    private String sim;
    private int alarmFlag;
    private int flag;
    private boolean located; // 是否定位
    private double lat;
    private double lng;
    private int height;     // 海拔高度,单位为米( m)
    private int speed;      // 1/10km/h
    private int direction;  // 0 ~ 359,正北为 0,顺时针
    @ClusteringColumn
    private UUID uuid;
    @Transient
    private Date time;

    public static Location fromDataPack(DataPack<LocationReport> dp) {
        Location l = new Location();
        LocationReport r = dp.getBody();
        l.sim = dp.getSim();
        l.alarmFlag = r.getAlarmFlag();
        l.flag = r.getFlag();
        l.located = r.isLocated();
        l.lat = r.getLat();
        l.lng = r.getLng();
        l.height = r.getHeight();
        l.speed = r.getSpeed();
        l.direction = r.getDirection();
        l.time = r.getTime();
        l.uuid = UUIDs.timeBased();
        return l;
    }

    public String getSim() {
        return sim;
    }

    public void setSim(String sim) {
        this.sim = sim;
    }

    public int getAlarmFlag() {
        return alarmFlag;
    }

    public void setAlarmFlag(int alarmFlag) {
        this.alarmFlag = alarmFlag;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public boolean isLocated() {
        return located;
    }

    public void setLocated(boolean located) {
        this.located = located;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }
}
